package com.googlecode.mavenjavacodegenplugin;

import japa.parser.ASTHelper;
import japa.parser.ast.CompilationUnit;
import japa.parser.ast.PackageDeclaration;
import japa.parser.ast.body.*;
import japa.parser.ast.expr.*;
import japa.parser.ast.stmt.BlockStmt;
import japa.parser.ast.type.VoidType;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Sebastian Prehn <sebastian.prehn@planetswebdesign.de>
 */
public class ModelExample {
    
    public static Set<CompilationUnit> getModel() {
        Set<CompilationUnit> result = new HashSet<CompilationUnit>();
        CompilationUnit cu = new CompilationUnit();
        cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("com.example")));
        ClassOrInterfaceDeclaration classDeclaration = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "HelloWorld");
        MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC | ModifierSet.STATIC, new VoidType(), "main");
        ASTHelper.addParameter(method, ASTHelper.createParameter(ASTHelper.createReferenceType("String", 1), "entity"));
        BlockStmt body = new BlockStmt();
        ASTHelper.addStmt(body, new MethodCallExpr(new FieldAccessExpr(new NameExpr("System"),"out"),"println",Arrays.asList((Expression) new StringLiteralExpr("Hello World"))));
        method.setBody(body);
        classDeclaration.setMembers(Arrays.asList((BodyDeclaration) method));
        cu.setTypes(Arrays.asList((TypeDeclaration)classDeclaration));
        result.add(cu);
        return result;
    }
    
}
